package com.zyh.reader;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @Author zyh
 * @Date 2024/8/5 15:03
 * @Description 一次读写一个字符
 */

public class ReaderAndWriter {

    public static void main2(String[] args) throws IOException {
        /*
        一个字符的读和写
         */
        FileReader fr = new FileReader("D:\\course\\02-JavaSE进阶\\day09-IO流\\素材\\c.java");
        FileWriter fw = new FileWriter("D:\\course\\02-JavaSE进阶\\day09-IO流\\素材\\b\\a.java");
        int len=-1;
        while ((len=fr.read())!=-1){
            fw.write(len);
        }
        fw.close();
        fr.close();
    }


    public static void main1(String[] args) throws IOException {
        /*
        一个字符的写
         */
        String str="hello java,你好世界";
        FileWriter fw = new FileWriter("D:\\course\\02-JavaSE进阶\\day09-IO流\\素材\\c.java");
        int len=-1;
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            fw.write(((char) aChar));
        }
        fw.close();
    }
}
